package cn.kgc.userservice.controller;

import cn.kgc.blogcommon.pojo.User;
import cn.kgc.userservice.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/register")
    public Map<String, Object> register(@RequestBody User user){
        System.out.println("进入service层了："+user.toString());
        Map<String, Object> map = new HashMap<>();
        //添加用户
        if(userService.addUser(user)){
            map.put("result", 1);
            map.put("message", "注册成功，请登录系统");
        } else {
            map.put("result", 0);
            map.put("message", "系统繁忙，请稍后重试");
        }
        return map;
    }

    //根据ID查找用户
    @ResponseBody
    @GetMapping("getUserById")
    public User getUserById(Integer userId){
        System.out.println("user-service服务接收usersId:" + userId);
        return userService.getUserById(userId);
    }

}
